package dungnt.vpoint.mathtest;

import dungnt.vpoint.mathtest.highscore.HighScoreMain;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ToggleButton;

public class MainActivity extends Activity implements OnClickListener{

	private Button btnPlay;
	private Button btnMoreGame;
	private Button btnInformation;
	private Button btnHighScore;
	private Button btnSound;
	private Button btnTimer;
	Context context;
	public static boolean blsound = true;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
		        WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_main);
		
		context = this;
		
		
		btnPlay = (Button)findViewById(R.id.btnPlay);
		btnPlay.setOnClickListener(this);
		btnMoreGame = (Button)findViewById(R.id.btnMoreGame);
		btnMoreGame.setOnClickListener(this);
		btnInformation = (Button)findViewById(R.id.btnInformation);
		btnInformation.setOnClickListener(this);
		btnHighScore = (Button)findViewById(R.id.btnHighScore);
		btnHighScore.setOnClickListener(this);
		btnSound = (ToggleButton)findViewById(R.id.btnSound);
		btnSound.setOnClickListener(this);
		btnTimer = (ToggleButton)findViewById(R.id.btnTimer);
		btnTimer.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnPlay:
		    Intent i_play = new Intent(this, PlayActivity.class);
		    startActivity(i_play);
		    break;
		case R.id.btnMoreGame:
		    Intent i_moregame = new Intent(this, MoreGameActivity.class);
		    startActivity(i_moregame);
		    finish();
		    break;
		case R.id.btnInformation:
		    Intent i_info = new Intent(this, InformationActivity.class);
		    startActivity(i_info);
		    finish();
		    break;
		case R.id.btnHighScore:
			Intent i_highscore = new Intent(this, HighScoreMain.class);
			startActivity(i_highscore);
			finish();
		    break;
		case R.id.btnSound:
		    break;
		case R.id.btnTimer:
		    break;
		}
	}

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Exit!")
                    .setMessage("Are you sure you want to exit?")
                    .setCancelable(false)
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    MainActivity.this.finish();

                                }

                            })
                    .setNegativeButton("Cancel",
                            new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    dialog.cancel();

                                }
                            });
            builder.create().show();
        }

        return super.onKeyDown(keyCode, event);
    }

	
}
